package com.jic.manager.impl;

import com.jic.common.base.vo.AdminOperate;
import com.jic.common.base.vo.Page;
import com.jic.common.base.vo.PageResult;
import com.jic.manager.common.util.BeanUtil;
import com.jic.manager.entity.MerchantWeBankContractFile;
import com.jic.manager.mapper.MerchantWeBankContractFileMapper;
import com.jic.manager.request.MerchantWeBankContractFileRequest;
import com.jic.manager.service.MerchantWeBankContractFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 商户合同附件表
 * @author : 
 * @email : 
 * @since : 2020-11-28 11:09:07
 * @version : v1.0.0
 */
@Service
public class MerchantWeBankContractFileServiceImpl implements MerchantWeBankContractFileService{

    @Autowired
    private MerchantWeBankContractFileMapper merchantWeBankContractFileMapper;

    @Override
    public long insert(MerchantWeBankContractFile merchantWeBankContractFile) {
        long flag = merchantWeBankContractFileMapper.insert(merchantWeBankContractFile);
        return flag;
    }

    @Override
    public long delete(Long id) {
        return merchantWeBankContractFileMapper.delete(id);
    }

    @Override
    public long update(MerchantWeBankContractFile merchantWeBankContractFile) {
        return merchantWeBankContractFileMapper.update(merchantWeBankContractFile);
    }

    @Override
    public MerchantWeBankContractFile queryByPrimaryKey(Long id){
        return merchantWeBankContractFileMapper.queryByPrimaryKey(id);
    }

    @Override
    public List<MerchantWeBankContractFile> query(MerchantWeBankContractFile merchantWeBankContractFile){
        return merchantWeBankContractFileMapper.query(merchantWeBankContractFile);
    }

    @Override
    public PageResult<MerchantWeBankContractFile> queryPage(MerchantWeBankContractFile merchantWeBankContractFile, Page pageQuery) {
        //计算下标
        int startIndex = (pageQuery.getStart() - 1) * pageQuery.getLimit();
        List<MerchantWeBankContractFile> list = merchantWeBankContractFileMapper.queryPage(startIndex, pageQuery.getLimit(), merchantWeBankContractFile);
        long count = merchantWeBankContractFileMapper.queryPageCount(merchantWeBankContractFile);
        PageResult pageResult = new PageResult();
        pageResult.setRows(list);
        pageResult.setTotal(count);
        return pageResult;
    }

    /**
     * 新增合同文件 无合同关联关系
     * @param request
     * @return
     */
    @Override
    public MerchantWeBankContractFile addContractFile(MerchantWeBankContractFileRequest request) {
        AdminOperate adminOperate = request.getAdminOperate();
        MerchantWeBankContractFile merchantWeBankContractFile = BeanUtil.copy(request, MerchantWeBankContractFile.class);
        merchantWeBankContractFile.setCreator(adminOperate.getOperator());
        merchantWeBankContractFile.setCreatorName(adminOperate.getOperateName());
        merchantWeBankContractFile.setDeptId(adminOperate.getDeptId());
        merchantWeBankContractFile.setCreateTime(new Date());
        merchantWeBankContractFileMapper.insert(merchantWeBankContractFile);
        return merchantWeBankContractFile;
    }
}